package com.jifeng.api.crud.controller;

import com.jifeng.api.crud.entity.UserEntity;
import com.jifeng.api.crud.service.UserService;
import com.jifeng.api.utils.PageUtils;
import com.jifeng.api.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 
 *
 * @author jifeng
 * @email 1593140625@qq.com
 * @date 2020-10-09 19:08:59
 */
@RestController
@RequestMapping("crud/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 登录
     */
    @PostMapping("/login")
    public R login(@RequestBody UserEntity userEntity){
        R rs=userService.login(userEntity);
        return rs;
    }

    /**
     * 统计各表中数据的数量
     */
    @GetMapping("/pc/count")
    public R countData (){
      R rs=  userService.countData();
      return rs;
    }

    /**
     * 查询用户列表
     */
    @GetMapping("/pc/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = userService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 根据省份和城市获取用户名列表
     */
    @GetMapping("/pc/name/list")
    public R listByProvince(@RequestParam Map<String, Object> params){
        R rs=userService.listByProvince(params);
        return rs;
    }
    /**
     * 增加用户
     */
    @PostMapping("/pc/add")
    public R add(@RequestBody UserEntity userEntity){
        R rs=userService.add(userEntity);
        return rs;
    }

    /**
     * 修改用户密码
     */
    @PostMapping("/pc/updPassword")
    public R updPassword(@RequestBody UserEntity userEntity){
        R rs=userService.updPassword(userEntity);
        return rs;
    }

    /**
     * 逻辑删除用户
     */
    @PostMapping("/pc/del")
    public R del(@RequestBody UserEntity userEntity){
	R rs=	userService.del(userEntity);
        return rs;
    }
}
